<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{baseui/head :: head}">
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="动检通智慧云平台"/>
    <meta name="author" content="牧中(上海)物联网科技有限公司"/>
    <link rel="shortcut icon" href="/webjars/images/favicon.png"/>
    <link rel="stylesheet" href="/webjars/js/layui/css/layui.css" media="all">
    <title>牧中畜牧业大数据智慧云平台V1.0</title>


</head>
<body>
<!--顶部一级导航-->
<th:block th:replace="baseui/topheader :: topheader(1)"/>

<!--动检通菜单-->
<th:block th:replace="djt/partial/topnav :: topnav(2)"/>


<div id="cl-wrapper">
    <!--左边导航-->
    <th:block th:replace="djt/partial/prod_left :: nav(8)"/>

    <div class="container-fluid" id="pcont">
        <!--<div class="page-head">-->
        <!--<h3>生产记录</h3>-->
        <!--</div>-->


        <div class="row">
            <div class="col-md-12">
                <div class="block-flat">
                    <div class="header"><h3>检验检测</h3></div>
                    <div class="content">
                        <div class="table-responsive">
                            <div id="datatable_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">


                                <div class="row">

                                    <!-- search-->

                                    <div style="white-space: nowrap">
                                        <div class="row" style="margin-left: 110px">
                                            <div class="col-sm-2">
                                                <div class="input-group date datetime col-md-5 col-xs-7"
                                                     data-min-view="2" data-date-format="yyyy-mm-dd">
                                                    <input id="start" class="form-control" style="width: 90px;"
                                                           size="16"
                                                           type="text" value="" placeholder="开始时间" readonly>
                                                    <span class="input-group-addon btn btn-primary"><span
                                                            class="glyphicon glyphicon-th"></span></span>
                                                </div>
                                            </div>
                                            <div class="col-sm-2">
                                                <div class="input-group date datetime col-md-5 col-xs-7"
                                                     data-min-view="2" data-date-format="yyyy-mm-dd">
                                                    <input id="end" class="form-control" style="width: 90px;" size="16"
                                                           type="text" value="" placeholder="结束时间" readonly>
                                                    <span class="input-group-addon btn btn-primary"><span
                                                            class="glyphicon glyphicon-th"></span></span>
                                                </div>


                                            </div>

                                            <span style="margin-left: 40px">   区域:
                                                           <select class="select2" style="max-width: 120px;"
                                                                   onchange="showfactory()" id="city">
                                                           <option value="全部">所有区域</option>
                                                               <span th:each="cityAreaDto :${cityAreaDtoList}">
                                                            <optgroup th:label="${cityAreaDto.city}">
                                                                <span th:each="region :${cityAreaDto.regions}">
                                                            <option th:value="${region}"
                                                                    th:text="${region}">南漳县</option>
                                                                    </span>
                                                          </optgroup>
                                                                   </span>
                                                                 </select>

                                            </span>
                                            <span style="margin-left: 50px">   养殖场:


                                                           <select class="select2" style="max-width: 165px;"
                                                                   id="factory">

                                                                       <option value='-1' selected>所有养殖场</option>
                                                                    <span th:each=" breedFactory :${breedFactoryList}">
                                                                  <option th:text="${breedFactory.name}"
                                                                          th:value="${breedFactory.id}">选项 1</option>

                                                                   </span>


                                                       </select>

                                                         </span>




                                        </div>
                                    </div>
                                    <div class="row" style="margin-left: 50px;">

                                        <span style="margin-left: 50px">   畜种:
                                                           <select class="select2" style="max-width: 100px;"
                                                                   id="breedType">
                                                               <option value="-1">全部</option>
                                                               <option value="1">猪 </option>
                                                               <option value="2">牛 </option>
                                                               <option value="3">羊 </option>
                                                               <option value="4">家禽</option>

                                                                 </select>

                                            </span>
                                        <span style="margin-left: 40px">   检测项目:
                                                           <select class="select2" style="max-width: 100px;"
                                                                   id="immunityType">
                                                               <option value="-1">全部</option>

                                                                 </select>

                                            </span>

                                        <span style="margin-left: 40px">
                                                <button class="btn btn-primary" onclick="SearchBtn()">搜索</button>
                                                </span>
                                    </div>


                                    <!--
                                                                            <div class="col-sm-6">
                                                                            <div id="datatable_filter" class="dataTables_filter">
                                                                            <label>区域:<select class="select2">
                                                                                <option value="所有区域">所有区域</option>
                                                                                <optgroup label="襄阳市">
                                                                                    <option value="南漳县">南漳县</option>
                                                                                    <option value="其它县">其它县</option>
                                                                                </optgroup>
                                                                            </select>


                                                                            </label></div>
                                                                            </div>
                                                                        </div>
                                    -->
                                    <div class="row">
                                        <div class="col-sm-12">

                                            <!-- Table -->
                                            <table id="jqGrid"></table>
                                            <div id="jqGridPager"></div>

                                        </div>
                                    </div>


                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>

<script type="text/javascript" src="/webjars/js/jquery.js"></script>

<script type="text/javascript" src="/webjars/js/jquery.nanoscroller/jquery.nanoscroller.js"></script>
<script type="text/javascript" src="/webjars/js/behaviour/general.js"></script>
<script src="/webjars/js/jquery.ui/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript" src="/webjars/js/jquery.nestable/jquery.nestable.js"></script>

<script type="text/javascript" src="/webjars/js/bootstrap.switch/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="/webjars/js/jquery.select2/select2.min.js" type="text/javascript"></script>

<script src="/webjars/js/bootstrap.slider/js/bootstrap-slider.js" type="text/javascript"></script>
<script type="text/javascript" src="/webjars/js/jquery.niftymodals/js/jquery.modalEffects.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.summernote/dist/summernote.min.js"></script>


<script type="text/javascript" src="/webjars/js/jquery.magnific-popup/dist/jquery.magnific-popup.min.js"></script>


<script src="/webjars/js/behaviour/voice-commands.js"></script>
<script src="/webjars/js/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/ecmascript" src="/webjars/jqgrid/js/i18n/grid.locale-cn.js"></script>
<script type="text/ecmascript" src="/webjars/jqgrid/js/jquery.jqGrid.min.js"></script>
<script src="/webjars/js/layui/layui.js" charset="utf-8"></script>

<script type="text/javascript">
    var PostDatas = {breedFactoryId: factoryoption()};
    $(document).ready(function () {

        App.init();

        //grid
        $("#jqGrid").jqGrid({
            url: '/djt/breedarch/ImmunizationDetection/select',
            postData: PostDatas,
            mtype: "post",
            styleUI: 'Bootstrap',
            datatype: "json",
            autowidth: true,
            shrinkToFit: true,
            colModel: [
                {label: '<span style="text-align: center">序号</span>', name: 'id', key: true, width: 75, align: 'center'},
                {label: '<span style="text-align: center">养殖场名称</span>', name: 'breedFactoryName', width: 200, align: 'center'},
                {label: '<span style="text-align: center">采样数量</span>', name: 'quantity', width: 100, align: 'center'},
                {label: '<span style="text-align: center">检测项目</span>', name: 'type', width: 100, align: 'center', formatter: ShowMethod},
                {label: '<span style="text-align: center">合格率</span>', name: 'qualifiedRate', width: 100, align: 'center', formatter: Showqu},
                {label: '<span style="text-align: center">日期</span>', name: 'date', width: 200, formatter: ShowDate, align: 'center'},
                {label: '<span style="text-align: center">详细</span>', width: 200, align: 'center', formatter: ShowOpertator}
            ],
            viewrecords: true,
            height: 350,

            rowNum: 20,
            pager: "#jqGridPager"
        });

    });
    function city() {

        var city = $("#city").val();


        if (city == "全部") {
            var array1 = new Array();
            $("#city option").each(function () {  //遍历所有option
                var txt = $(this).val();   //获取option值
                if (txt != '') {
                    array1.push(txt);  //添加到数组中
                }
            });

            return array1.toString();
        } else {
            var array2 = new Array();
            array2.push(city);
            return array2.toString();
        }

    }

    function showfactory() {


        var type = $("#breedType").val();

        $.ajax({

            url: "/djt/breedarch/search",
            data: {region: city(), breedType: type},
            dataType: "json",
            success: function (data) {

                $("#factory").empty();

                if (data.length != 0) {
                    var str1 = " <option value='-1' selected>所有养殖场</option>";
                    $("#factory").append(str1);
                    $.each(data, function (index, obj) {
                        var id = obj.id;
                        var name = obj.name;
                        var str = "<option value=" + id + ">" + name + "</option>";

                        $("#factory").append(str);
                    });
                } else {

                    var str = "<option value='0' selected>无</option>";
                    $("#factory").append(str);
                }
            }
        });
    }
    function factoryoption() {

        var factory_id = $("#factory").val();


        if (factory_id == -1) {
            var array1 = new Array();
            $("#factory option").each(function () {  //遍历所有option
                var txt = $(this).val();   //获取option值
                if (txt != '') {
                    array1.push(txt);  //添加到数组中
                }
            });

            return array1.toString();
        } else if (factory_id == 0) {
            var array3 = new Array();
            array3.push(factory_id);
            return array3.toString();

        } else {
            var array2 = new Array();
            array2.push(factory_id);
            return array2.toString();
        }

    }
    // 搜索
    var SearchBtn = function () {
        var time1 = $("#start").val();
        var time2 = $("#end").val();
        if (time1 == "") {
            time1 = new Date("2000-01-01 :00:00:00");
        } else {
            time1 = new Date(time1);
        }

        if (time2 == "") {
            time2 = new Date();
        } else {
            time2 = new Date(time2);
        }
        var breedType = $("#breedType").val();
        var immunityType = $("#immunityType").val();
        var sdata = {   // 构建查询需要的参数
            type: immunityType,
            breedFactoryId: factoryoption(),
            breedType: breedType,
            time1: time1,
            time2: time2
        };


        var postData = $("#jqGrid").jqGrid("getGridParam", "postData");

        $.extend(postData, sdata);

        $("#jqGrid").jqGrid("setGridParam", {
            search: true    // (6)将jqGrid的search选项设为true
        }).trigger("reloadGrid", [{page: 1}]);   // (7)重新载入Grid表格，以使上述设置生效

    }
    //    时间格式化
    function ShowDate(cellvalue, options, rowObject) {

        var timestamp4 = new Date(cellvalue);
        var dt = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
        return dt;
    }


    //检测项目
    function ShowMethod(cellvalue, options, rowObject) {
        var type;
        switch (cellvalue) {
            case 101:
                type = "猪瘟";
                break;
            case 102:
                type = "口蹄疫";
                break;
            case 103:
                type = "蓝耳病";
                break;
            case 104:
                type = "瘦肉精";
                break;
            case 301:
                type = "羊血吸虫病";
                break;
            case 302:
                type = "羊布病";
                break;
            case 303:
                type = "羊小反刍兽疫";
                break;
            case 304:
                type = "瘦肉精";
                break;
            case 201:
                type = "牛血吸虫病";
                break;
            case 202:
                type = "牛布病";
                break;
            case 203:
                type = "瘦肉精";
                break;
            case 401:
                type = "禽流感";
                break;

            case 402:
                type = "新城疫";
                break;
            case 999:
                type = "其它";
                break;
        }
        return type;
    }

    //查看
    function ShowOpertator(cellvalue, options, rowObject) {
        var link;
        var rowval = rowObject["id"];

        var row = JSON.stringify(rowObject);

        link = "<button type='button' class='btn btn-default' id='" + row + "' onclick='select(this.id)'>查看</button><button type='button' class='btn btn-default' id='" + row + "' onclick='delete1(this.id)'>删除</button>";

        return link;
    }

    //合格率
    function Showqu(cellvalue, options, rowObject) {
        var type = cellvalue;
        type = type + "%";
        return type;
    }

    // 猪疾病
    var PIGILLNESS = {
        101: '猪瘟',
        102: '口蹄疫',
        103: '蓝耳病',
        104: '(猪)瘦肉精'

    }
    // 羊疾病
    var SHEEPILLNESS = {
        301: '羊血吸虫病',
        302: '羊布病',
        303: '羊小反刍兽疫',
        304: '（羊）瘦肉精'

    }
    // 牛疾病
    var CATTLEILLNESS = {
        201: '牛血吸虫病',
        202: '牛布病',
        203: '（牛）瘦肉精'

    }
    // 家禽疾病
    var POULTRYILLNESS = {
        401: '禽流感',
        402: '新城疫',
        999: '其它'
    }


    function imtion() {

        for (var key in PIGILLNESS) {
            var str = "<option value=" + key + ">" + PIGILLNESS[key] + "</option>";
            $("#immunityType").append(str);
        }
        for (var key1 in SHEEPILLNESS) {
            var str = "<option value=" + key1 + ">" + SHEEPILLNESS[key1] + "</option>";
            $("#immunityType").append(str);
        }
        for (var key2 in CATTLEILLNESS) {
            var str = "<option value=" + key2 + ">" + CATTLEILLNESS[key2] + "</option>";
            $("#immunityType").append(str);
        }
        for (var key3 in POULTRYILLNESS) {
            var str = "<option value=" + key3 + ">" + POULTRYILLNESS[key3] + "</option>";
            $("#immunityType").append(str);
        }
    }
    imtion();


    function getarea(a) {

        var type;
        switch (a) {
            case 1:
                type = "繁殖区";
                break;
            case 2:
                type = "保育区";
                break;
            case 3:
                type = "育肥区";
                break;
        }
        return type;
    }
    function select(data) {


        var json = JSON.parse(data);
        var area=getarea(json.area);
        var timestamp4 = new Date(json.date);
        var dt = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
        var type = ShowMethod(json.type, null, null);
        var qualifiedRate = Showqu(json.qualifiedRate, null, null);
        layui.use(['laypage', 'layer'], function () {
            var $ = layui.jquery, layer = layui.layer;


            layer.open({
                type: 2,
                skin: 'layui-layer-lan',
                area: ['800px', '500px'],
                content: ['/djt/breedarch/ImmunizationDetectiondetail', 'no'],
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];

                    body.find("#breedFactoryName").text(json.breedFactoryName);
                    body.find("#number").text(json.number);
                    body.find("#area").text(area);
                    body.find("#stableNumber").text(json.stableNumber);

                    body.find("#date").text(dt);
                    body.find("#type").text(type);
                    body.find("#quantity").text(json.quantity);
                    body.find("#detectionOrganization").text(json.detectionOrganization);
                    body.find("#qualifiedRate").text(qualifiedRate);


                }
            });


        });
    }

    function delete1(data) {
        var json = JSON.parse(data);
        layui.use(['laypage', 'layer'], function () {
            var $ = layui.jquery, layer = layui.layer;


            layer.msg('确定删除吗？', {
                time: 60000, //20s后自动关闭
                btn: ['确定', '取消'],
                btnAlign: 'c',
                btn1: function (index, layero) {

                    $.ajax({

                        url: "/djt/breedarch/ImmunizationDetectionDelete",
                        data: {
                            id: json.id,

                        },
                        dataType: "json",
                        success: function (data) {
                            if (data) {
                                layer.msg('删除成功', {
                                    time: 60000, //20s后自动关闭
                                    btn: '确定',
                                    btnAlign: 'c',
                                    btn1: function (index, layero) {
                                        window.location.href ="/djt/breedarch/ImmunizationDetection";
                                    }
                                })

                            }else {
                                layer.msg('删除失败请重试', {
                                    time: 60000, //20s后自动关闭
                                    btn: '确定',
                                    btnAlign: 'c',
                                    btn1: function (index, layero) {
                                        window.location.href ="/djt/breedarch/ImmunizationDetection";
                                    }
                                })
                            }
                        }
                    })
                }

            })


        });

    }




</script>

<script src="/webjars/js/laydate/laydate.js"></script>

</body>
</html>
